package com.aspose.cells.a.d;

public class zed extends zfe {
   private zee b;
   private zew d;
   private boolean g;
   private zev h;

   public zed(zdh var1, zee var2) throws Exception {
      this(var1, var2, false);
   }

   public zed(zdh var1, zee var2, boolean var3) throws Exception {
      super(var1);
      this.b = var2;
      this.g = var3;
   }

   public void b(zeg var1) throws Exception {
      var1.a("/Type", "/XObject");
      var1.a("/Subtype", "/Image");
      var1.a("/Width", this.b.b());
      var1.a("/Height", this.b.c());
      this.c(var1);
      var1.a("/BitsPerComponent", this.h());
      if (this.b.f() && !this.e.b().u()) {
         this.h = new zev(this.e, this.b.l(), this.b.b(), this.b.c());
         var1.a("/SMask", this.h.n());
      }

   }

   public void a(zeg var1) throws Exception {
      if (this.i()) {
         this.c();
      } else {
         byte[] var2 = this.g ? this.b.l() : this.b.k();
         this.a(var2, 0, var2.length);
      }

      this.b.n();
      super.a(var1);
      if (this.d != null) {
         this.d.a(var1);
      }

      if (this.h != null) {
         this.h.a(var1);
      }

   }

   private void c(zeg var1) throws Exception {
      zdg var2 = this.g();
      if (var2 != zdg.c()) {
         var1.a("/ColorSpace", com.aspose.cells.b.a.zv.a("/{0}", var2.e()));
      } else {
         this.d();
         var1.a("/ColorSpace", com.aspose.cells.b.a.zv.a("[/{0}/DeviceRGB {1} {2}]", var2.e(), this.b.m().length - 1, this.d.n()));
      }

   }

   private void c() throws Exception {
      switch(this.e.b().c()) {
      case 4:
         zbk.a(this.b.a(), this.e(), this.e.b().d());
         break;
      case 5:
         zbk.a(this.b.a(), this.e(), 3, false);
         break;
      case 6:
         zbk.a(this.b.a(), this.e(), 4, false);
         break;
      default:
         throw new Exception("Unknown image compression.");
      }

   }

   private void d() throws Exception {
      this.d = new zew(this.e);

      for(int var1 = 0; var1 < this.b.m().length; ++var1) {
         this.d.a(this.b.m()[var1].getR());
         this.d.a(this.b.m()[var1].getG());
         this.d.a(this.b.m()[var1].getB());
      }

   }

   public static void a(zew var0, zee var1) throws Exception {
      var0.c("BI");
      var0.a("/W " + var1.b());
      var0.a("/H " + var1.c());

      assert var1.e() != zdg.c();

      var0.a("/CS/" + var1.e().f());
      var0.c("/BPC " + var1.d());
      var0.a("ID ");
      var0.a(var1.k(), 0, var1.k().length);
      var0.a("\r\n");
      var0.c("EI");
   }

   private zdg g() {
      if (this.g) {
         return zdg.a();
      } else if (this.e.b().h() == 6) {
         return zdg.a();
      } else {
         return this.i() ? zdg.b() : this.b.e();
      }
   }

   private int h() throws Exception {
      if (this.g) {
         return 8;
      } else {
         return this.e.b().h() == 6 ? 1 : this.b.d();
      }
   }

   protected boolean b() {
      return true;
   }

   private boolean i() {
      return !this.g && this.e.b().f() && this.b.a() != null;
   }
}
